package com.da.javatest.leetCode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chenlida
 * @date 2019/1/4 19:45
 * @description
 */
public class Code566 {
    public int[][] matrixReshape(int[][] nums, int r, int c) {
        if (r * c != nums.length * nums[0].length) {return nums;}
        int[][] result = new int[r][c];
        List<Integer> rs = new ArrayList<>(r * c);
        for (int i = 0; i < nums.length; i++) {
            for (int j = 0; j < nums[0].length; j++) {
                rs.add(nums[i][j]);
            }
        }
        int index = 0;
        for (int i = 0; i < result.length; i++) {
            for (int j = 0; j < result[0].length; j++) {
                result[i][j] = rs.get(index++);
            }
        }
        return result;
    }
}
